package com.coincalf.admin.service;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.admin.dto.AccountDTO;
import com.coincalf.admin.entity.Account;
import com.baomidou.mybatisplus.service.IService;
import com.coincalf.framework.enums.BusinessType;
import com.coincalf.framework.exception.AccountException;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;

/**
 * <p>
 * 用户财产记录 服务类
 * </p>
 *
 * @author qiang
 * @since 2018-05-13
 */
public interface AccountService extends IService<Account> {

    /**
     * 分页查询
     *
     * @param var1
     * @param var2
     * @return
     */
    Page<Account> selectListPage(Page<Account> var1, Wrapper<Account> var2);

    /**
     * 查询资金账户
     *
     * @param userId 用户ID
     * @param coinId 币种ID
     * @return
     */
    Account queryByUserIdAndCoinId(long userId, long coinId);

    /**
     * 解冻资金
     *
     * @param userId       用户ID
     * @param coinId       币种ID
     * @param amount       冻结金额
     * @param businessType 业务类型
     * @param orderId      关联订单号
     * @return
     */
    boolean unlockAmount(long userId,
                         long coinId,
                         BigDecimal amount,
                         BusinessType businessType,
                         long orderId
    ) throws AccountException;

    /**
     * 扣减资金
     *
     * @param userId       用户ID
     * @param coinId       币种ID
     * @param amount       冻结金额
     * @param businessType 业务类型
     * @param remark       备注
     * @param orderId      关联订单号
     * @return
     */
    boolean subtractAmount(long userId,
                           long coinId,
                           BigDecimal amount,
                           BusinessType businessType,
                           String remark,
                           long orderId) throws AccountException;

    /**
     * 资金划转
     *
     * @param fromUserId   转出用户ID
     * @param toUserId     转入用户ID
     * @param coinId       币种ID
     * @param amount       金额
     * @param businessType 业务类型
     * @param orderId      关联订单号
     * @param remark       备注
     * @return
     */
    boolean transferAmount(long fromUserId,
                           long toUserId,
                           long coinId,
                           BigDecimal amount,
                           BusinessType businessType,
                           long orderId,
                           String remark) throws AccountException;

    /**
     * 后台充值
     *
     * @param accountDTO
     * @param businessType 业务类型
     * @return
     * @throws AccountException
     */
    boolean rechargeAmount(AccountDTO accountDTO,
                           BusinessType businessType) throws AccountException;
}
